/* 创建数组的几种方式 */
{
    let arr1 = [3, 4, 7, 9, 11];
    let arr2 = new Array(3, 4, 7, 9, 11);
    let arr3 = Array.of(3, 4, 7, 9, 11);
    let arr4 = Array.from([3, 4, 7, 9, 11]);
}

/* 增加元素 */
{
    let arr1 = [3, 4, 7, 9, 11];
    arr1.push(99);
    console.log(arr1);
}

/* 访问 */
{
    let array = ["apple", "banana", "orange"];
    console.log(array.length);
    console.log(array[1]);  // banana
    let index = array.indexOf("banana");
    console.log(index);     // 1
}

/* py的map,filter */
{
    let array = [1, 3, 5];
    /* 类似py的map+lambda的效果 */
    let mapArr = Array.from(array, function (item) { return item * 2 });
    /* 类似py的filter+lambda的效果 */
    let filterArr = array.find(function (item) { return item > 1 });
    /* js还多了个对index的过滤 */
    let filterIndexArr = array.findIndex(function (item) { return item > 1 });
}

/* 是否包含元素 */ 
{
    let isInclude = [1,2,NaN].includes(1);  // true
}

/* 遍历数组 */
{
    let arr1 = [3, 4, 7, 9, 11];
    arr1.forEach(
        function (item) {
            console.log(item);
        }
    );
}

/* Js的数组可以当成一个Map, key为下标,value为值 */
{
    let array = ['1', 'c', 'ks'];
    for (let index of array.keys()) {
        console.log('key', index);
        console.log('value', array[index]);
    }
    for (let [index, value] of ['1', 'c', 'ks'].entries()) {
        console.log('values', index, value);
    }
}